package com.ionidea;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

class Employee implements Comparable<Employee>{
	private int Id;
	private String Name;
	private String DepartmentId;
	private String Gender;
	private double Salary;
	private String ManagerName;
	public Employee(){}
	public Employee(int id, String name, String departmentId, String Gender,
			double salary, String managerName) {
		super();
		this.Id = id;
		this.Name = name;
		DepartmentId = departmentId;
		this.Gender = Gender;
		this.Salary = salary;
		this.ManagerName = managerName;
	}
	public int getId() {
		return Id;
	}
	public void setId(int id) {
		Id = id;
	}
	public String getName() {
		return Name;
	}
	public void setName(String name) {
		Name = name;
	}
	public String getDepartmentId() {
		return DepartmentId;
	}
	public void setDepartmentId(String departmentId) {
		DepartmentId = departmentId;
	}
	public String getGender() {
		return Gender;
	}
	public void setGender(String Gender) {
		Gender = Gender;
	}
	public double getSalary() {
		return Salary;
	}
	public void setSalary(double salary) {
		Salary = salary;
	}
	public String getManagerName() {
		return ManagerName;
	}
	public void setManagerName(String managerName) {
		ManagerName = managerName;
	}
	public String toString(){
		return Id+"\t"+Name+"\t"+DepartmentId+"\t"+Gender+"\t"+Salary+"\t"+ManagerName;
	}
	@Override
	public int compareTo(Employee o) {
		
		return this.Id-o.Id;
	}
}
public class SortEmployeeDetails {
public static void main(String[] args) {
	ArrayList<Employee> list=new ArrayList<Employee>();
	list.add(new Employee(105, "deepak", "D03", "Male", 27000.0, "chetan"));
	list.add(new Employee(102, "kumar", "D01", "Male", 25000.0, "amit"));
	list.add(new Employee(101, "Neha", "D05", "Female", 20000.0, "deepak"));
	System.out.println("------Sort by ID-------");
	Collections.sort(list);
	for(Employee emp:list){
		System.out.println(emp);
	}
	System.out.println("------Sort by Name-------");
	ArrayList<Employee> list1=new ArrayList<Employee>();
	list1.add(new Employee(105, "deepak", "D03", "Male", 27000.0, "chetan"));
	list1.add(new Employee(102, "kumar", "D01", "Male", 25000.0, "amit"));
	list1.add(new Employee(101, "Neha", "D05", "Female", 20000.0, "deepak"));
	
	Collections.sort(list1, new SortByName());
	for(Object emp2:list1){
		System.out.println(emp2);
	}
}
}
class SortByName implements Comparator{

	@Override
	public int compare(Object obj1, Object obj2) {
		Employee e1=(Employee)obj1;
		Employee e2=(Employee)obj2;
		String name1=e1.getName();
		String name2=e2.getName();
		return name1.compareTo(name2);
	}
	
}
